﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace Infancy.Core.Plugin.Configuration {
    public class PluginConfigurationElementCollection : System.Configuration.ConfigurationElementCollection {
        protected override ConfigurationElement CreateNewElement() {
            return new PluginConfigurationElement(Guid.NewGuid());
        }

        protected override object GetElementKey(ConfigurationElement element) {
            return ((PluginConfigurationElement)element).Name;
        }

        protected override string ElementName {
            get {
                return "Plugin";
            }
        }

        public PluginConfigurationElement this[int index] {
            get { 
                return (PluginConfigurationElement)BaseGet(index); 
            }
            set {
                if (BaseGet(index) != null) {
                    BaseRemoveAt(index);
                }
                BaseAdd(index, value);
            }
        }

        public new PluginConfigurationElement this[string name] {
            get {
                return (PluginConfigurationElement)BaseGet(name);
            }
            set {
                if (BaseGet(name) != null) {
                    BaseRemove(name);
                }
                BaseAdd(value);
            }
        }

        public int IndexOf(PluginConfigurationElement element) {
            return BaseIndexOf(element);
        }

        public override ConfigurationElementCollectionType CollectionType {
            get {
                return ConfigurationElementCollectionType.BasicMap;
            }
        }

        public PluginConfigurationElementCollection() {
        }

        [ConfigurationProperty("Path")]
        public string Path {
            get { return Convert.ToString(base["Path"]); }
            set { base["Path"] = value; }
        }
    }
}
